var accountBillCtrl  = new XFApp.client();
$.views.converters({	
	fmoney : function(value) {		
		if(!value){
			return "0.00";
		}		
		return moneyCtrl.money.fmoney(value,2);		
	},
});
XFApp.client.prototype.accountBill = {
		successCode : 10000,	
		accountBillPage : null,
		urlItems : {
			initListURL: basePath+"/userCenter/accountBill/query",
			paymentSubmitURL: basePath+"/userCenter/accountBill/submit",
		},
		
		event : function (){			
			_this = this;		
			var reqTimeStart ;
			var reqTimeEnd ;			
			var chargeType = 0;
			var paymentStatus = 3;
			var refNo ;
			//全部
			$("#all").on("click",function(){				
				$('#paymentStatus #pending').removeClass('active');
				$('#paymentStatus #complete').removeClass('active');
				$('#paymentStatus #failure').removeClass('active');
				$('#paymentStatus #all').addClass('active');				
				paymentStatus = 3;
				//参数 支付状态,费用类型,订单号,日期
				_this.load(paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd);
			});
			
			//待支付
			$("#pending").on("click",function(){								
				$('#paymentStatus #all').removeClass('active');
				$('#paymentStatus #complete').removeClass('active');
				$('#paymentStatus #failure').removeClass('active');
				$('#paymentStatus #pending').addClass('active');				
				paymentStatus = 0;
				_this.load(paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd);
			});
			
			//已支付
			$("#complete").on("click",function(){								
				$('#paymentStatus #all').removeClass('active');
				$('#paymentStatus #pending').removeClass('active');
				$('#paymentStatus #failure').removeClass('active');
				$('#paymentStatus #complete').addClass('active');
				paymentStatus = 1;					
				_this.load(paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd);
			});
			
			//支付失败
			$("#failure").on("click",function(){								
				$('#paymentStatus #all').removeClass('active');
				$('#paymentStatus #pending').removeClass('active');
				$('#paymentStatus #complete').removeClass('active');
				$('#paymentStatus #failure').addClass('active');
				paymentStatus = 2;				
				_this.load(paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd);
			});
			
			$("#searchBtn").on("click",function(){				
				reqTimeStart = $("#reqTimeStart").val();
				reqTimeEnd = $("#reqTimeEnd").val();
				chargeType = $("#chargeType").val();
				refNo = $("#refNo").val();				
				_this.load(paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd);
			});
			
			//支付
			$("#payment").on("click",function(){
				
				var params = {
					userWalletId : $("#userWalletId").val(),
					accountBillId : $("#accountBillId").val(),
				}
			    	
			    $.ajax({
						url : _this.urlItems.paymentSubmitURL,
						data : params,
						dataType : "json",
						type : 'post',
						success : function(data) {
							if (data.code == _this.successCode) {
								webAlert({
					                title:'提示',
					                content: data.msg,
					                opacity:.5,
					                bg:"gray",
					                width:300,
					                height:10,
					                button:[
					                        {
					                        name:"确定",
					                        callback:function(){
					                        	window.location = basePath + "/userCenter/accountBill";
					                        	this.close();
					                        }
					                        }]
					            });
								
								
							} else {
								window.webDialogUtil.alert("提示", data.msg);
							}
						}
			    	});
			});
			
		},	
		
		load : function (paymentStatus,chargeType,refNo,reqTimeStart,reqTimeEnd){		
			var searchParams = {
				chargeType:chargeType,
				paymentStatusType:paymentStatus,
				reqTimeStart:reqTimeStart,
			    reqTimeEnd:reqTimeEnd,
			    refNo:refNo,
    		};
			if(!!_this.accountBillPage){
				_this.accountBillPage.page("remote",0,searchParams);
			}else{
				_this.accountBillPage = $("#page").page({
				pageSize : 10,
				remote: {
					url: _this.urlItems.initListURL,
			        params: searchParams, 
			        success: function (data, pageIndex) {
			        	if(data.code==_this.successCode){
			        		if(null == data.result 
										|| null == data.result.itemList
											|| data.result.itemList.length < 1
												|| null == data.result.itemList[0]){
			        			$("#page_grid").html('<tr><td align="center" colspan="15">暂无数据</td></tr>');
			        		}else{			        			
			        			$("#page_grid").html($("#pageTmp").render(data.result.itemList));			        			
			        		}
			        		
			        	}else{
			        		  window.webDialogUtil.alert("提示",data.msg);
			        	}
			        },
			        error : function(){
			        	window.webDialogUtil.alert("提示",data.msg);
			        }
				},
				firstBtnText : '首页',
				lastBtnText : '尾页',
				prevBtnText : '上一页',
				nextBtnText : '下一页',
				showInfo : true,
				showJump : true,
				jumpBtnText : '跳转',
				showPageSizes : true,
				infoFormat : '共{pageCount}页'
			});	
		   }			
		},
		
		
		
},

$(function(){	
	
	accountBillCtrl.accountBill.event();	
	//默认查询全部
	//参数 支付状态,费用类型,支付订单号,日期
	accountBillCtrl.accountBill.load(3,0,null,null,null);
	
});